const app = getApp()

Page({
  data: {
    wh: '',
    tabList: [
      { title: '预售秒杀' },
      { title: '领券即省' },
      { title: '即买即送' },
      { title: '历史抄底' },
    ],
    topBanner: '/images/top.gif',
    titleImg1: '/images/t1.jpg',
    titleImg2: '/images/t2.jpg',
    titleCon2: '/images/t2-con.png',
    titleImg3: '/images/t3.jpg',
    titleCon3: '/images/t3-con.png',
    titleImg4: '/images/t4.png',
    titleCon4: '/images/t4-con.png',
    navShow: false,
    current: 0,
    // topNum: 0,
    scrollTop: {
      scroll_top: 0,
      goTop_show: false
    }

  },
  scroll: function (e) {
    this.setData({
      intoView: "view" + e.currentTarget.dataset.id
    })
  },
  onLoad() {
    let that = this;
    wx.getSystemInfo({
      success({ windowHeight }) {
        console.log(windowHeight)
        let h = windowHeight
        that.setData({
          wh: windowHeight
        })
      }
    });

  },
  scrollTopFun: function (e) {
    let _scrollTop = e.detail.scrollTop;
    let progress = parseInt((_scrollTop) / this.data.wh) + 1; // 计算出 当前的下标
    console.log(_scrollTop, this.data.wh, progress)
    let len = this.data.tabList.length;
    if (_scrollTop > 200) {
      this.setData({
        'navShow': true
      });
    } else {
      this.setData({
        'navShow': false
      });
    }
    if (_scrollTop > 300) {//触发gotop的显示条件
      this.setData({
        'scrollTop.goTop_show': true,
      });
    } else {
      this.setData({
        'scrollTop.goTop_show': false,
      });
    }
  },
  // 循环切换
  forTab(index) {
    let lens = this.data.tabList.length;
    let _id = 'view' + index;
    this.setData({
      intoView: _id,
      current: index
    });
  },
  // 返回顶部
  goTopFun: function (e) {
    var _top = this.data.scrollTop.scroll_top;//发现设置scroll-top值不能和上一次的值一样，否则无效，所以这里加了个判断
    if (_top == 1) {
      _top = 0;
    } else {
      _top = 1;
    }
    this.setData({
      'scrollTop.scroll_top': _top
    });
  }
})
